//get state-level IIM and standard errors for them

use cz kfr_native_pooled_pooled_p25 kfr_pooled_pooled_p25 kfr_native_pooled_pooled_p25_se kfr_pooled_pooled_p25_se  ///
kfr_native_pooled_pooled_n kfr_pooled_pooled_n kfr_stycz_pooled_pooled_p25 kfr_stycz_pooled_pooled_p25_se kfr_stycz_pooled_pooled_n using "$data/Opp_Atlas/cz_outcomes", clear

merge 1:1 cz using "$data/LOO/onlinedata8", keep(match) nogen
keep cz stateabbrv pop2000 kfr*
gen count = 1
collapse (sum) count (mean) kfr_pooled_pooled_p25 kfr_native_pooled_pooled_p25 kfr_stycz_pooled_pooled_p25 ///
kfr_pooled_pooled_p25_se kfr_native_pooled_pooled_p25_se kfr_stycz_pooled_pooled_p25_se [fw = kfr_native_pooled_pooled_n], by(state)

//merge on state fips codes
ren state state
merge m:1 state using "$data/Crosswalks/state_fips_crosswalk", keep(match) nogen
drop if statefips == 11

//keep the stuff that we care about
sort statefips
preserve
keep kfr_native_pooled_pooled_p25
export delimited "$dir/Model/moments/state_iim.csv", novarn replace
restore

preserve
keep kfr_native_pooled_pooled_p25_se 
export delimited "$dir/Model/boot/state_iim_se.csv", novarn replace
restore






//end of dofile